<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/vue-2.6.12.js"></script>
</head>

<body>
    <div id="app">
        <input type="button" value="浪起来" @click="lang">
        <input type="button" value="低调" @click="didiao">

        <h4>{{ msg }}</h4>
    </div>

    <script>
        // 在vm实例中，想要调用 data 上的数据，或者 methods 里的方法，必须通过 this，
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '猥琐发育，稳住别浪~~！',
                timerId: null
            },
            methods: {
                lang: function () {
                    if (this.timeId != null) return;

                    this.timeId = setInterval(() => {
                        let start = this.msg.substring(0, 1);
                        let end = this.msg.substring(1);
                        this.msg = end + start;
                    }, 500)
                },
                didiao() {
                    clearInterval(this.timeId);
                    this.timeId = null;
                }
            }
        })
    </script>
</body>

</html>